package org.kl.bf.entity.basic;

import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.kl.bf.entity.AuditableEntity;
import org.kl.bf.entity.Excel;
import org.kl.bf.entity.JavaType;
import org.kl.bf.utils.BasicConstants;

//JPA标识
@Entity
@Table(name = "basic_excel_config")
public class ExcelConfig extends AuditableEntity {
	private static final long serialVersionUID = 7347557546365562667L;

	@Excel(exportName = "导入编号", exportProperty = "importNo")
	private ExcelImport excelImport;

	@Excel(exportName = "中文列名")
	private String chineseName;
	@Excel(exportName = "字段名称")
	private String columnName;
	@Excel(exportName = "序列编号")
	private Integer columnNo;
	@Excel(exportName = "java类型", exportProperty = "codeName")
	private CodeValues codeValues;
	@Excel(exportName = "是否外键")
	private Integer isForeignKey;
	@Excel(exportName = "是否联合唯一")
	private Integer isUnionUnique;
	@Excel(exportName = "关联表名称")
	private String foreignTableName;
	@Excel(exportName = "关联字段名称")
	private String fkColumnName;
	@Excel(exportName = "关联表的辅助字段名称")
	private String foreignTableAssistColumnName;
	@Excel(exportName = "是否是辅助字段")
	private Integer isAssistColumn;
	@Excel(exportName = "辅助关联表名称")
	private String assistForeignTableName;
	@Excel(exportName = "辅助关联字段名称")
	private String assistFkColumnName;
	@Excel(exportName = "辅助值Excel列数")
	private Integer assistExcelColumnNo;
	@Excel(exportName = "其他关联字段集")
	private String otherColumns;
	@Excel(exportName = "其他关联字段值")
	private String otherValues;
	@Excel(exportName = "转换Map")
	private String convertMap;

	private CodeValues editType;

	/**
	 * 通过convertMap转换好的Map对应：[columnName：Map<String,String>]
	 */
	private Map<String, Object> columnConvertMap;

	/**
	 * 该字段对应的Java类型
	 */
	private Class<?> propertyClass;

	@ManyToOne
	@JoinColumn(name = "excel_import_id")
	public ExcelImport getExcelImport() {
		return excelImport;
	}

	public void setExcelImport(ExcelImport excelImport) {
		this.excelImport = excelImport;
	}

	public String getChineseName() {
		return chineseName;
	}

	public void setChineseName(String chineseName) {
		this.chineseName = chineseName;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public Integer getColumnNo() {
		return columnNo;
	}

	public void setColumnNo(Integer columnNo) {
		this.columnNo = columnNo;
	}

	@ManyToOne
	@JoinColumn(name = "java_type")
	public CodeValues getCodeValues() {
		return codeValues;
	}

	public void setCodeValues(CodeValues codeValues) {
		this.codeValues = codeValues;
		if (codeValues != null && StringUtils.isNotBlank(codeValues.getCodeValue())) {
			propertyClass = Enum.valueOf(JavaType.class, codeValues.getCodeValue()).getValue();
		}
	}

	public Integer getIsForeignKey() {
		return isForeignKey;
	}

	public void setIsForeignKey(Integer isForeignKey) {
		if (isForeignKey == null) {
			this.isForeignKey = BasicConstants.NO_INT;
		} else {
			this.isForeignKey = isForeignKey;
		}
	}

	public Integer getIsUnionUnique() {
		return isUnionUnique;
	}

	public void setIsUnionUnique(Integer isUnionUnique) {
		if (isUnionUnique == null) {
			this.isUnionUnique = BasicConstants.NO_INT;
		} else {
			this.isUnionUnique = isUnionUnique;
		}
	}

	public String getForeignTableName() {
		return foreignTableName;
	}

	public void setForeignTableName(String foreignTableName) {
		this.foreignTableName = foreignTableName;
	}

	public String getFkColumnName() {
		return fkColumnName;
	}

	public void setFkColumnName(String fkColumnName) {
		this.fkColumnName = fkColumnName;
	}

	@Column(name = "foreign_table_assist_name")
	public String getForeignTableAssistColumnName() {
		return foreignTableAssistColumnName;
	}

	public void setForeignTableAssistColumnName(String foreignTableAssistColumnName) {
		this.foreignTableAssistColumnName = foreignTableAssistColumnName;
	}

	public Integer getIsAssistColumn() {
		return isAssistColumn;
	}

	public void setIsAssistColumn(Integer isAssistColumn) {
		this.isAssistColumn = isAssistColumn;
	}

	public String getAssistForeignTableName() {
		return assistForeignTableName;
	}

	public void setAssistForeignTableName(String assistForeignTableName) {
		this.assistForeignTableName = assistForeignTableName;
	}

	public String getAssistFkColumnName() {
		return assistFkColumnName;
	}

	public void setAssistFkColumnName(String assistFkColumnName) {
		this.assistFkColumnName = assistFkColumnName;
	}

	public Integer getAssistExcelColumnNo() {
		return assistExcelColumnNo;
	}

	public void setAssistExcelColumnNo(Integer assistExcelColumnNo) {
		this.assistExcelColumnNo = assistExcelColumnNo;
	}

	public String getOtherColumns() {
		return otherColumns;
	}

	public void setOtherColumns(String otherColumns) {
		this.otherColumns = otherColumns;
	}

	public String getOtherValues() {
		return otherValues;
	}

	public String getConvertMap() {
		return convertMap;
	}

	public void setConvertMap(String convertMap) {
		this.convertMap = convertMap;
	}

	public void setOtherValues(String otherValues) {
		this.otherValues = otherValues;
	}

	@Transient
	public Class<?> getPropertyClass() {
		return propertyClass;
	}

	@Transient
	public Map<String, Object> getColumnConvertMap() {
		return columnConvertMap;
	}

	public void setColumnConvertMap(Map<String, Object> columnConvertMap) {
		this.columnConvertMap = columnConvertMap;
	}

	@Transient
	public CodeValues getEditType() {
		return editType;
	}

	public void setEditType(CodeValues editType) {
		this.editType = editType;
	}

}
